const Router = require('koa-router')

const {
 upload, create,
 update, remove,
 remove_2, restore,
 findAll
} = require('../controller/goods.controller')
const {
 auth,
 hadAdminPermission
} = require('../middleware/auth.middleware')
const {
 validator
} = require('../middleware/goods.middleware')


const router = new Router({ prefix: '/goods' })

// 上传文件
router.post('/upload', auth, hadAdminPermission, upload)
// 上架商品
router.post('/', auth, hadAdminPermission, validator, create)
// 修改商品
router.put('/:id', auth, hadAdminPermission, validator, update)
// 硬删除(删除数据库中的数据)
router.delete('/:id', auth, hadAdminPermission, remove)
// 软删除(修改数据库中的数据)--下架
router.post('/:id/off', auth, hadAdminPermission, remove_2)
// 恢复--上架
router.post('/:id/on', auth, hadAdminPermission, restore)
// 获取商品列表
router.get('/', findAll)

module.exports = router
